Why do some files have file endings?

For the why, two reasons, makes it easier for humans to identify a file just by looking at the filename but also useful for programs to the same kind of file but with different purpose. Java sourcecode, python sourcecode, c++ sourcecode...that are all just text. And identifying the exact programming language in them can be complicated (java and c++ have a lot of keywords in common, it's no trivial to see if a program is written for Java or c++). So by having file extensions it is a lot easier for editors to turn on the correct syntax highlighting for a specific language for example.

So, why do people always say that linux (unix) has no file extensions? Well, because there really aren't any...You have one filename and that filename can end in dot-something but it has no special meaning at all. It's not like the FAT filesystem where each file has a filename and an extra data field for the extension. The file extension in unix filesystems is simply a part of the filename. And file extensions don't have to be done by ".<something>"...for example vim creates backup files simply by adding a "~" at the end of the filename. The "extension" in this case is only "~" without any dot.

The traditional way of identifying a file on unix is by "magic numbers". You have a long list of "byte combinations" and something reads the start of a file then compares it to that list to see what the file really is. The file tool for example does this...you can have a look at the magic number list in /usr/share/misc/magic. That folder has text files for all filetypes file can identify which tell file what numbers it has to find in the start of a file to identify it as this filetype.

But that is not the end of it....nowadays there is a second system for identifying files: shared-mime-info. This is mostly used by DEs and their programs. And mimetypes defined by this database can either be defined again by magic numbers but also by filename patterns. The database files for this system you can find in /usr/share/mime (or if you modify them on your user account in ~/.local/share/mime). And if you look at examples there most contain a <glob pattern="*.png"/> line or similar. That means any program using the mimetype database will identify png images by matching he filename against a "*.png" pattern. Filename matching is simply faster than having to open a file and look at the start...so for your filemanager being able to display the "filetype" column in time this is nicer...even if it doesn't guarantee that the file is really a png image.

So nowadays there is hardly any filesystem left in use with extra extension support. All OSes and programs do it the same as unix now, extensive filetype detection with magic number (If you try to open a file in a program usually) and quick filetype detection by pattern-matching on the filename (for displaying filetype in filemanager or such).